<?php
//
// +------------------------------------------------------------------------+
// | Gecko Framework                                                        |
// +------------------------------------------------------------------------+
//

/**
 * Creates a new Form tag
 *
 * @param string $destination
 * @param string $name
 * @param string $method
 * @param string $multipart
 * @param string $target
 * @return string
 */
function form_tag( $destination, $name, $method = 'post', $multipart = false, $target= '' ) {
	$encType = "application/x-www-form-urlencoded";
	if( $multipart ) $encType = "multipart/form-data";
	if( !empty( $target ) ) $target = " target=\"$target\"";

	$form = "<form action=\"$destination\" method=\"$method\" enctype=\"$encType\" name=\"$name\" id=\"$name\"$target>";

	return $form;
}

/**
 * Creates a new Time input widget
 *
 * @param string $name
 * @param string $value
 * @param array $params
 * @return string
 */
function input_time($name, $value='', $params=array()) {
	$time = new Gecko_Form_Field_Time($name, $value, $params);

	return $time->getControl();
}

/**
 * Creates a new Select widget via a SQL
 * DataSource
 *
 * @param string $name
 * @param string $query
 * @param string $value
 * @param boolean $addEmpty
 * @param string $emptyLabel
 * @param array $params
 * @return string
 */
function input_select_sql( $name, $query, $value = '', $addEmpty = false, $emptyLabel = ' - Select - ', $params = array() ) {
	$db = $params['db'];
	if(!$db) {
		$params['db'] = Gecko_DB::getInstance();
	}
	$params['sql'] = $query;

	$select = new Gecko_Form_Field_SelectSQL($name, $value, $params);
	return $select->getControl();
}

/**
 * Creates a new Select widget from a Array of options
 *
 * @param string $name
 * @param array $select_options
 * @param string $value
 */
function input_select($name, $select_options, $value = '') {
	$ds = new Gecko_DataSource_Select_Array($select_options);
	$params = array('source' => $ds);

	$select = new Gecko_Form_Field_Select($name, $value, $params);
	return $select->getControl();
}

/**
 * Creates a new DatePicker widget
 *
 * @param string $name
 * @param string $value
 * @param array $params
 */
function input_date( $name, $value = "", $params = array() ) {
	$date = new Gecko_Form_Field_Date($name, $value, $params);
	return $date->getControl();
}

/**
 * Creates a new Color picker
 *
 * @param string $name
 * @param string $value
 * @return string
 */
function input_color( $name, $value = "" ) {
	$color = new Gecko_Form_Field_ColorPicker($name, $value);

	return $color->getControl();
}

function input_text( $name, $value = '', $params = array() ) {
	$text = new Gecko_Form_Field_Text($name, $value, $params);

	return $text->getControl();
}
?>